package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

type ExpressFeeSetting struct {
	ID                   string `json:"id" gorm:"primaryKey;column:id;type:uint;size:64;comment:唯一ID"`
	Name                 string `json:"name" gorm:"column:name;type:string;size:20;comment:模版名称"`
	ShippingFromProvince string `json:"shipping_from_province" gorm:"column:shipping_from_province;type:int;size:64;comment:发货地址-省份"`
	ShippingFromCity     string `json:"shipping_from_city" gorm:"column:shipping_from_city;type:int;size:64;comment:发货地址-城市"`
	PricingType          int    `json:"pricing_type" gorm:"column:pricing_type;type:int;size:8;comment:计价方式 1-计件 2-计重"`
	FreeShippingProvince string `json:"free_shipping_province" gorm:"column:free_shipping_province;type:text;包邮区域"`
	PricingConfig        string `json:"pricing_config" gorm:"column:pricing_config;type:json;comment:计件配置"`
	Default              int    `json:"default" gorm:"column:default;type:int;size:8;default:2;comment:是否默认，1-默认 2-否"`
	CreatedAt            int64  `gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间" json:"created_at"`
	UpdatedAt            int64  `gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:修改时间" json:"updated_at"`
}

func (ExpressFeeSetting) TableName() string {
	return "express_fee_setting"
}

// BeforeCreate 自增id
func (m *ExpressFeeSetting) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &ExpressFeeSetting{})
}
